<template>
  <el-dialog :title="admininfo.title" :visible.sync="admininfo.show" width="600px">
    <el-form :model="parames" :rules="rules" label-width="150px" ref="adminInfo">
      <el-form-item label="用户名:">
        <el-input v-model="parames.userName" autocomplete="off" :disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="二级域名:" prop="domain">
        <el-input v-model="parames.domain" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="推广的APP名称:" prop="appName">
        <el-input v-model="parames.appName" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="admininfo.show = false">取 消</el-button>
      <el-button type="primary" @click="handleSend">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  data() {
    return {
      parames: {},
      rules: {
          domain: [
            { required: true, message: '请输入二级域名', trigger: 'blur' },
          ],
          appName: [
            { required: true, message: '请输入推广的APP名称', trigger: 'blur' },
          ]
      }
    };
  },
  props: ["admininfo"],
  methods: {
    handleClose() {
      this.admininfo.show = false;
    },
    render() {
      this.$axios.get("/tx/profile/info").then(res => {
        if (res.code === 10200) {
          this.parames = res.data;
        }
      });
    },
    resetData () {
        this.$refs.adminInfo.resetFields();
    },
    handleSend() {
      this.$axios
        .post("/tx/profile/info/update", {
          id: this.parames.id,
          type: this.parames.type,
          userName: this.parames.userName,
          domain: this.parames.domain,
          appName: this.parames.appName
        })
        .then(res => {
          if (res.code === 10200) {
            this.$message({
              message: "操作成功！",
              type: "success"
            });
            setTimeout(() => {
                this.handleClose()
            }, 200);
          }
        });
    }
  },
  computed: {
    changeDialog() {
      return this.admininfo.show;
    }
  },
  watch: {
    changeDialog(culval) {
      if (culval) {
        this.render();
      } else {
        this.resetData()
      }
    }
  }
};
</script>
<style>
</style>
